﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.Library.Core.Utils.Media
{
    public class MediaUtils
    {
        public static string MediaContent(string container, string audioFile)
        {
            return MediaContent(container, audioFile, string.Empty, string.Empty, string.Empty);
        }
        public static string MediaContent(string container, string audioFile, string imageFile, string title, string link)
        {
            return MediaContent(container, audioFile, imageFile, title, link, string.Empty, 0, 0);
        }
        public static string MediaContent(string container, string audioFile, string imageFile, string title, string link, string skin, int width, int height)
        {
            string strContainer = (string.IsNullOrEmpty(container)) ? "MainPlayer" : container;
            string strAudioFile = (string.IsNullOrEmpty(audioFile)) ? "/ClientScript/Player/demo.mp3" : audioFile;
            string strTitle = (string.IsNullOrEmpty(title)) ? "Mạng Việt Nam - go.vn" : title;
            string strLink = (string.IsNullOrEmpty(link)) ? "http://go.vn/" : link;
            string strImageFile = (string.IsNullOrEmpty(imageFile)) ? "/ClientScript/Player/go_logo.png" : imageFile;
            string strSkin = (string.IsNullOrEmpty(skin)) ? "/ClientScript/Player/skin/newtubedark.zip" : skin;
            int strWidth = (width > 0) ? width : 470;
            int strHeight = (height > 0) ? height : 265;

            StringBuilder sb = new StringBuilder();
            sb.Append("<script type=\"text/javascript\">\r\n");
            sb.Append("    var fileUrl = \"" + strAudioFile + "\";\r\n");
            sb.Append("    jwplayer(\"" + strContainer + "\").setup({\r\n");
            sb.Append("        id: \"" + strContainer + "\",\r\n");
            sb.Append("        image: \"" + strImageFile + "\",\r\n");
            sb.Append("        autoStart: true,\r\n");
            sb.Append("        width: " + strWidth + ",\r\n");
            sb.Append("        height: " + strHeight + ",\r\n");
            sb.Append("        volume: 100,\r\n");
            sb.Append("        controlbar: { position: \"over\" },\r\n");
            sb.Append("        skin: \"" + strSkin + "\",\r\n");
            sb.Append("        abouttext: \"" + strTitle + "\",\r\n");
            sb.Append("        aboutlink: \"" + strLink + "\",\r\n");
            sb.Append("        modes: [\r\n");
            sb.Append("                { type: \"flash\", src: \"/ClientScript/Player/player.swf\" },\r\n");
            sb.Append("                { type: \"html5\" },\r\n");
            sb.Append("                { type: \"download\" }\r\n");
            sb.Append("            ],\r\n");
            sb.Append("        plugins: {\r\n");
            sb.Append("            'http://my.go.vn/c/Player/logo_plugin.swf': {}\r\n");
            sb.Append("        },\r\n");
            sb.Append("        levels: [\r\n");
            sb.Append("            { file: fileUrl },\r\n");
            sb.Append("            { file: fileUrl.replace('.flv', '.mp4') },\r\n");
            sb.Append("            { file: fileUrl.replace('.flv', '.3gp') }\r\n");
            sb.Append("        ]\r\n");
            sb.Append("    }); \r\n");
            sb.Append("</script>");
            return sb.ToString();
        }
    }
}
